package logic

import (
	"context"
	"shunovel/shunovelrpc/shunovelrpc"

	"shunovel/api/internal/svc"
	"shunovel/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BookAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBookAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BookAddLogic {
	return &BookAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BookAddLogic) BookAdd(req *types.BookAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.ShuNovelRpc.BookAdd(l.ctx, &shunovelrpc.BookAddRequest{
		Title:  req.Title,
		Image:  req.Image,
		Text:   req.Text,
		UserId: int64(req.UserId),
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "图书添加成功",
		Data:    add,
		Code:    200,
	}, nil

}
